package it.kion.util.ui.umenumanager2.views;

import it.kion.util.ui.umenumanager2.IImageKeys;
import it.kion.util.ui.umenumanager2.UMenuManager;
import it.kion.util.ui.umenumanager2.adapter.MenuItemsAdapterFactory;
import it.kion.util.ui.umenumanager2.epinterfaces.IMenuContributor;
import it.kion.util.ui.umenumanager2.epinterfaces.IMenuContributor.ActionTarget;
import it.kion.util.ui.umenumanager2.listener.MenuSelectionChangeListener;
import it.kion.util.ui.umenumanager2.model.Folder;
import it.kion.util.ui.umenumanager2.model.Item;
import it.kion.util.ui.umenumanager2.model.MenuItem;
import it.kion.util.ui.umenumanager2.parser.MenuDOMParser;
import it.kion.util.ui.umenumanager2.preferences.UMenuManagerPreferencePage;
import it.kion.util.ui.umenumanager2.utils.PathConverter;
import it.kion.util.ui.umenumanager2.views.decorator.MenuManagerLabelDecorator;

import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.HashMap;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.part.DrillDownAdapter;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.plugin.AbstractUIPlugin;

/**
 * This sample class demonstrates how to plug-in a new workbench view. The view shows data obtained from the model. The sample creates a
 * dummy model on the fly, but a real implementation would connect to the model available either in this or another plug-in (e.g. the
 * workspace). The view is connected to the model using a content provider.
 * <p>
 * The view uses a label provider to define how model objects should be presented in the view. Each view can present the same model objects
 * using different labels and icons, if needed. Alternatively, a single label provider can be shared between views in order to ensure that
 * objects of the same type are presented in the same way everywhere.
 * <p>
 */

public class MenuManagerView extends ViewPart {

	public static final String SIAPR_WEB_NEW_PATH = "\\siapr-web\\build\\classes\\WEB-INF\\desktop.xml";

	private TreeViewer treeViewer;

	private Text infoText, infoTextGen;

	private DrillDownAdapter drillDownAdapter;

	/*
	 * Actions
	 */
	private Action actionOpenBP;

	private Action actionOpenView;

	private Action actionOpenHierarchy;
	
	private Action actionOpenComponent;

	private Action actionExpandAll;

	private Action actionCollapseAll;
	
	private Action actionRefreshTree;

	private Action doubleClickAction;

	private MenuItemsAdapterFactory adapterFactory = new MenuItemsAdapterFactory();

	/*
	 * Images & ImageDescriptor
	 */
	private static HashMap<String, Image> images = null;

	private static HashMap<String, ImageDescriptor> imageDescriptors = null;

	class ViewContentProvider implements IStructuredContentProvider, ITreeContentProvider {

		private TreeParent invisibleRoot;

		public void inputChanged(Viewer v, Object oldInput, Object newInput) {}

		public void dispose() {}

		public Object[] getElements(Object parent) {
			if (parent.equals(getViewSite())) {
				if (invisibleRoot == null) initialize();
				return getChildren(invisibleRoot);
			}
			return getChildren(parent);
		}

		public Object getParent(Object child) {
			if (child instanceof TreeObject) {
				return ((TreeObject) child).getParent();
			}
			return null;
		}

		public Object[] getChildren(Object parent) {
			if (parent instanceof TreeParent) {
				return ((TreeParent) parent).getChildren();
			}
			return new Object[0];
		}

		public boolean hasChildren(Object parent) {
			if (parent instanceof TreeParent) return ((TreeParent) parent).hasChildren();
			return false;
		}

		/*
		 * We will set up a dummy model to initialize tree heararchy. In a real code, you will connect to a real model and expose its
		 * hierarchy.
		 */
		private void initialize() {
			refreshTree();
		}
		
	}

	class ViewLabelProvider extends LabelProvider {

		public String getText(Object obj) {
			String res = obj.toString();
			if (obj instanceof TreeParent) {
				res = res.toUpperCase();
			}
			return res;
		}

		public Image getImage(Object obj) {
			Image res = images.get("ITEM_IMG");
			if (obj instanceof TreeParent) {
				res = images.get("FOLDER_IMG");
			}
			return res;
		}
	}

	class NameSorter extends ViewerSorter {}

	/**
	 * The constructor.
	 */
	public MenuManagerView() {
		images = new HashMap<String, Image>();
		imageDescriptors = new HashMap<String, ImageDescriptor>();

		images.put("FOLDER", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.FOLDER).createImage());
		images.put("ITEM", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.ITEM).createImage());
		images.put("MDD", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.MDD).createImage());
		images.put("NEW_MDD", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.NEW_MDD).createImage());
		images.put("MDD_WARN", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.MDD_WARN).createImage());
		images.put("NEW_MDD_WARN", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.NEW_MDD_WARN).createImage());
		
		imageDescriptors.put("BP", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.BP));
		imageDescriptors.put("PLUS", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.PLUS));
		imageDescriptors.put("MINUS", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.MINUS));
		imageDescriptors.put("VIEW", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.VIEW));
		imageDescriptors.put("HIERARCHY", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.HIERARCHY));
		imageDescriptors.put("COMPONENT", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.COMPONENT));
		imageDescriptors.put("REFRESH", AbstractUIPlugin.imageDescriptorFromPlugin(UMenuManager.PLUGIN_ID, IImageKeys.REFRESH));
	}

	/**
	 * This is a callback that will allow us to create the viewer and initialize it.
	 */
	public void createPartControl(Composite parent) {
		setUp();

	    parent.setLayout(new FormLayout());

	    FormData data = new FormData();
	    
	    SashForm splitter = new SashForm(parent, SWT.VERTICAL);
	    data.top = new FormAttachment(0, 0); // Attach to top
	    data.bottom = new FormAttachment(100, 0);
	    data.left = new FormAttachment(0, 0);
	    data.right = new FormAttachment(100, 0);

	    splitter.setLayoutData(data);
    
	    treeViewer = new TreeViewer(splitter, SWT.BORDER | SWT.V_SCROLL);

	    // Informazioni generiche sul menu
	    infoTextGen = new Text(splitter, SWT.MULTI);
	    infoTextGen.setEditable(false);
	    Color azure = new Color(getSite().getShell().getDisplay(), 238, 238, 255);
	    infoTextGen.setBackground(azure);

	    // Informazioni specifiche sull'elemento selezionato
	    infoText = new Text(splitter, SWT.MULTI);
	    infoText.setEditable(false);
	    Color c = new Color(getSite().getShell().getDisplay(), 255, 255, 200);
	    infoText.setBackground(c);
	    
		drillDownAdapter = new DrillDownAdapter(treeViewer);
		treeViewer.setContentProvider(new ViewContentProvider());
		
		//Label provider
		ILabelProvider lp = new ViewLabelProvider();
		//Label decorator
		ILabelDecorator decorator = new MenuManagerLabelDecorator();
		
		treeViewer.setLabelProvider(new DecoratingLabelProvider(lp, decorator));
		
		// treeViewer.setSorter(new NameSorter());
		treeViewer.setInput(getViewSite());
		
		treeViewer.getTree().setToolTipText("");
		
		final Listener labelListener = new Listener () {
			public void handleEvent (Event event) {
				Label label = (Label)event.widget;
				Shell shell = label.getShell ();
				switch (event.type) {
					case SWT.MouseDown:
						Event e = new Event ();
						e.item = (TreeItem) label.getData ("_TABLEITEM");
						// Assuming table is single select, set the selection as if
						// the mouse down event went through to the table
						treeViewer.getTree().setSelection (new TreeItem [] {(TreeItem) e.item});
						treeViewer.getTree().notifyListeners (SWT.Selection, e);
						shell.dispose ();
						treeViewer.getTree().setFocus();
						break;
					case SWT.MouseExit:
						shell.dispose ();
						break;
				}
			}
		};
					
		Listener treeListener = new Listener () {
			Shell tip = null;
			Label label = null;
			public void handleEvent (Event event) {
				switch (event.type) {
					case SWT.Dispose:
					case SWT.KeyDown:
					case SWT.MouseMove: {
						if (tip == null) break;
						tip.dispose ();
						tip = null;
						label = null;
						break;
					}
					case SWT.MouseHover: {
						Point coords = new Point(event.x, event.y);
						TreeItem item = treeViewer.getTree().getItem(coords);
						if (item != null) {
							TreeObject to = (TreeObject) item.getData();
							if(!(to instanceof TreeParent)){
								Item function = (Item) to.getWrappedObj();
								if(function!=null && function.getWarnings().size()>0){
									int columns = treeViewer.getTree().getColumnCount();
									for (int i = 0; i < columns || i == 0; i++) {
										if (item.getBounds(i).contains(coords)) {
											if (tip != null  && !tip.isDisposed ()) tip.dispose ();
											tip = new Shell (treeViewer.getTree().getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
											tip.setBackground (treeViewer.getTree().getDisplay().getSystemColor (SWT.COLOR_INFO_BACKGROUND));
											FillLayout layout = new FillLayout ();
											layout.marginWidth = 2;
											tip.setLayout (layout);
											label = new Label (tip, SWT.NONE);
											label.setForeground (treeViewer.getTree().getDisplay().getSystemColor (SWT.COLOR_INFO_FOREGROUND));
											label.setBackground (treeViewer.getTree().getDisplay().getSystemColor (SWT.COLOR_INFO_BACKGROUND));
											label.setData ("_TABLEITEM", item);
											String messages = "";
											for(String message : function.getWarnings()){
												messages += "!- " + message + "\r\n";
											}
											label.setText (messages);
											
											label.addListener (SWT.MouseExit, labelListener);
											label.addListener (SWT.MouseDown, labelListener);
											Point size = tip.computeSize (SWT.DEFAULT, SWT.DEFAULT);
											Rectangle rect = item.getBounds (i);
											Point pt = treeViewer.getTree().toDisplay (rect.x, rect.y);
											tip.setBounds (pt.x, pt.y, size.x, size.y);
											tip.setVisible (true);
											break;
										}
									}									
								}
							}
						}
					}
				}
			}
		};
		treeViewer.getTree().addListener (SWT.Dispose, treeListener);
		treeViewer.getTree().addListener (SWT.KeyDown, treeListener);
		treeViewer.getTree().addListener (SWT.MouseMove, treeListener);
		treeViewer.getTree().addListener (SWT.MouseHover, treeListener);
		
		makeActions();
		hookContextMenu();
		hookDoubleClickAction();
		contributeToActionBars();
	}

	private void setUp() {}

	private void hookContextMenu() {
		MenuManager menuMgr = new MenuManager("#PopupMenu");
		menuMgr.setRemoveAllWhenShown(true);
		menuMgr.addMenuListener(new IMenuListener() {

			public void menuAboutToShow(IMenuManager manager) {
				ISelection selection = treeViewer.getSelection();
				Object obj = ((IStructuredSelection) selection).getFirstElement();
				if (obj instanceof TreeParent) {
					MenuItem i = (MenuItem) ((TreeParent)obj).getWrappedObj();
					fillContextMenuFromExtensions(manager, i);
				}
				else {
					MenuManagerView.this.fillContextMenu(manager, (TreeObject)obj);
				}
			}
		});
		Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
		treeViewer.getControl().setMenu(menu);
		getSite().registerContextMenu(menuMgr, treeViewer);
	}

	private void contributeToActionBars() {
		IActionBars bars = getViewSite().getActionBars();
		fillLocalPullDown(bars.getMenuManager());
		fillLocalToolBar(bars.getToolBarManager());
	}

	private void fillLocalPullDown(IMenuManager manager) {
		manager.add(actionOpenBP);
		manager.add(new Separator());
		manager.add(actionOpenView);
	}

	private void fillContextMenu(IMenuManager manager, TreeObject to) {
		manager.add(actionOpenBP);
		if(to!=null && to.getWrappedObj()!=null){
			Item i = (Item) to.getWrappedObj();
			fillContextMenuFromExtensions(manager, i);
			if(i.isMdd()){
				manager.add(actionOpenHierarchy);				
				manager.add(actionOpenComponent);				
			}
		}
		manager.add(actionOpenView);	
	}

	private void fillContextMenuFromExtensions(IMenuManager manager,
			MenuItem i) {
		try {
			IConfigurationElement[] config = Platform.getExtensionRegistry()
					.getConfigurationElementsFor(UMenuManager.IMENU_CONTRIB);
			for (IConfigurationElement e : config) {
				Object o = e.createExecutableExtension("class");
				if (o instanceof IMenuContributor) {
					IMenuContributor menucontrib = ((IMenuContributor) o);
					if(i.isFolder() && menucontrib.getActionTarget()==ActionTarget.FOLDER) {
						manager.add(menucontrib.getAction());
					} else if(!i.isFolder() && menucontrib.getActionTarget()!=ActionTarget.FOLDER) {
						manager.add(menucontrib.getAction());
					}
				}
			}
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}

	private void fillLocalToolBar(IToolBarManager manager) {
		manager.add(actionRefreshTree);
		manager.add(new Separator());
		manager.add(actionExpandAll);
		manager.add(actionCollapseAll);
		manager.add(new Separator());
		drillDownAdapter.addNavigationActions(manager);
	}

	private void makeActions() {
		actionOpenBP = new Action() {

			public void run() {
				ISelection selection = treeViewer.getSelection();
				Object obj = ((IStructuredSelection) selection).getFirstElement();
				if (obj instanceof TreeObject) {
					MenuItem mi = ((TreeObject) obj).getWrappedObject();
					if (mi instanceof Item) {
						UMenuManager.openResource(PathConverter.getPathForBP((Item) mi));
					}
				}
			}

			@Override
			public void runWithEvent(Event event) {
				super.runWithEvent(event);
			}

		};
		actionOpenBP.setText("Apri il BP");
		actionOpenBP.setToolTipText("Apre un'editor di Eclipse sul file indicato nel descrittore di menu nel tag <business-process> ");
		actionOpenBP.setImageDescriptor(imageDescriptors.get("BP"));

		actionOpenView = new Action() {

			public void run() {
				ISelection selection = treeViewer.getSelection();
				Object obj = ((IStructuredSelection) selection).getFirstElement();
				if (obj instanceof TreeObject) {
					MenuItem mi = ((TreeObject) obj).getWrappedObject();
					if (mi instanceof Item) {
						// showMessage(((Item) mi).getView());
						UMenuManager.openResource(PathConverter.getPathForView(((Item) mi).getView()));
					}
				}
			}

		};
		actionOpenView.setText("Apri la vista");
		actionOpenView.setToolTipText("Apre un'editor di Eclipse sul file indicato nel descrittore di menu nel tag <view-id> ");
		actionOpenView.setImageDescriptor(imageDescriptors.get("VIEW"));

		actionOpenHierarchy = new Action() {

			public void run() {
				ISelection selection = treeViewer.getSelection();
				Object obj = ((IStructuredSelection) selection).getFirstElement();
				if (obj instanceof TreeObject) {
					MenuItem mi = ((TreeObject) obj).getWrappedObject();
					if (mi instanceof Item) {
						UMenuManager.openResource(PathConverter.getPathForHierarchy(((Item) mi).getView()));
					}
				}
			}

		};
		actionOpenHierarchy.setText("Apri il file di hierarchy");
		actionOpenHierarchy.setToolTipText("Apre un'editor di Eclipse sul file di hierarchy");
		actionOpenHierarchy.setImageDescriptor(imageDescriptors.get("HIERARCHY"));
		
		actionOpenComponent = new Action() {

			public void run() {
				ISelection selection = treeViewer.getSelection();
				Object obj = ((IStructuredSelection) selection).getFirstElement();
				if (obj instanceof TreeObject) {
					MenuItem mi = ((TreeObject) obj).getWrappedObject();
					if (mi instanceof Item) {
						UMenuManager.openResource(PathConverter.getPathForComponent((Item) mi));
					}
				}
			}

		};
		actionOpenComponent.setText("Apri il componente EJB di backend");
		actionOpenComponent.setToolTipText("Apre un'editor di Eclipse sul componentne EJB di backend");
		actionOpenComponent.setImageDescriptor(imageDescriptors.get("COMPONENT"));
		
		actionExpandAll = new Action() {

			public void run() {
				expandAllMenu();
			}

		};
		actionExpandAll.setText("Espandi tutto");
		actionExpandAll.setToolTipText("Espande tutto il menu");
		actionExpandAll.setImageDescriptor(imageDescriptors.get("PLUS"));

		actionCollapseAll = new Action() {

			public void run() {
				collapseAllMenu();
			}

		};
		actionCollapseAll.setText("Riduci tutto");
		actionCollapseAll.setToolTipText("Riduce tutto il menu");
		actionCollapseAll.setImageDescriptor(imageDescriptors.get("MINUS"));

		actionRefreshTree = new Action() {

			public void run() {
				refreshTree();
			}

		};
		actionRefreshTree.setText("Refresh");
		actionRefreshTree.setToolTipText("Ricarica l'albero del menu");
		actionRefreshTree.setImageDescriptor(imageDescriptors.get("REFRESH"));

		
		
		doubleClickAction = new Action() {

			public void run() {
				ISelection selection = treeViewer.getSelection();
				Object obj = ((IStructuredSelection) selection).getFirstElement();
				if (obj instanceof TreeObject) {
//					MenuItem mi = ((TreeObject) obj).getWrappedObject();
//					if (mi instanceof Item) {
//						String text = "BP=" + ((Item) mi).getBusinessProcessClass() + "\n view: " + ((Item) mi).getView();
////						showMessage(PathConverter.getPathForView(((Item) mi).getView()));
//						setTextInfo(text);
//					}
				}
			}
		};
	}

	private void hookDoubleClickAction() {
		treeViewer.addDoubleClickListener(new IDoubleClickListener() {

			public void doubleClick(DoubleClickEvent event) {
				doubleClickAction.run();
			}
		});
	}

	public void expandAllMenu() {
		treeViewer.expandAll();
	}

	public void collapseAllMenu() {
		treeViewer.collapseAll();
	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
		treeViewer.getControl().setFocus();
	}

	public TreeViewer getTreeViewer() {
		return treeViewer;
	}

	public void setTextInfo(String infoMessage){
		infoText.setText(infoMessage);
		infoText.redraw();
	}
	
	public void setTextInfoGen(String infoGenMessage){
		infoTextGen.setText(infoGenMessage);
		infoTextGen.redraw();
	}

	public static Image getImage(String key){
		return images.get(key);
	}

	public void refreshTree(){
		String path = null;
		path = UMenuManager.getDefault().getPreferenceStore().getString(UMenuManagerPreferencePage.PREF_PATH_TO_DESKTOP_XML);
		try {
			UMenuManager.setParser(new MenuDOMParser());
			UMenuManager.getParser().run(path);
		}
		catch (NullPointerException e) {
			MessageBox mb = new MessageBox(this.getViewSite().getShell(), SWT.ICON_WARNING);
			mb.setText("ATTENZIONE!");			
			mb.setMessage("In valore impostato nelle preferenze di UMenuManager per il campo \"File (desktop.xml)\" non è corretto o il file non è presente. /r/n Modificare il valore di tale campo di preferenza e premere il pulsante di refresh sulla vista di UMenuManager per caricare correttamente tale vista.");
			mb.open();
		}
		catch (FileNotFoundException e) {
			MessageBox mb = new MessageBox(this.getViewSite().getShell(), SWT.ICON_WARNING);
			mb.setText("ATTENZIONE!");			
			mb.setMessage("In file impostato nelle preferenze di UMenuManager per il campo \"File (desktop.xml)\" non è presente. /r/n Modificare il valore di tale campo di preferenza e premere il pulsante di refresh sulla vista di UMenuManager per caricare correttamente tale vista.");
			mb.open();
		}

		TreeParent p1 = new TreeParent("desktop");

		Collection<Folder> mainFolders = UMenuManager.getMainFolders();

		for (Folder f : mainFolders) {
			TreeParent tp = new TreeParent(f.getLabel());
			iterateThroughChild(f, tp);
			p1.addChild(tp);
		}

		// Registering the adapter factory with Eclipse.
		Platform.getAdapterManager().registerAdapters(adapterFactory, Item.class);
		Platform.getAdapterManager().registerAdapters(adapterFactory, Folder.class);

		// invisibleRoot.addChild(p1);
		treeViewer.setInput(p1);
		treeViewer.collapseAll();
		treeViewer.addSelectionChangedListener(new MenuSelectionChangeListener(infoText));
		refreshMenuGenInto();
	}

	private void refreshMenuGenInto() {
		MenuDOMParser parser = UMenuManager.getParser();
		int numFunzioniNonFacelets = parser.getNumFunzioniNonFacelets();
		int numFunzioniFacelets = parser.getNumFunzioniFacelets();
		int numFunzioniNuovoMdd = parser.getNumFunzioniNuovoMdd();
		int numFunzioni = numFunzioniFacelets + numFunzioniNonFacelets;
		infoTextGen.selectAll();
		String text = "Numero funzioni totali: " + numFunzioni + "\r\n";
		infoTextGen.insert(text);
		text = "JSP: " + numFunzioniNonFacelets + "\r\n";
		infoTextGen.insert(text);
		text = "Facelets: " + numFunzioniFacelets + " (di cui " + numFunzioniNuovoMdd + " MDD2)\r\n";
		infoTextGen.insert(text);
		infoTextGen.redraw();
	}

	private void iterateThroughChild(Folder parentFolder, TreeParent tp) {
		for (Folder subFolder : parentFolder.getChildOfTypeFolder()) {
			TreeParent tps = new TreeParent(subFolder.getLabel());
			tp.addChild(tps);
			iterateThroughChild(subFolder, tps);
		}
		for (Item i : parentFolder.getChildOfTypeItem()) {
			TreeObject to = new TreeObject(i.getLabel());
			to.setWrappedObj(i);
			tp.addChild(to);
		}
	}
}
